#ifndef DETECTION_H
#define DETECTION_H 
#include <opencv/highgui.h>
#include <opencv/cv.h>
#define MAXPLATEWIDTH 90
#define MAXPLATEHEIGHT 20
#define MINPLATEWIDTH 60
#define MINPLATEHEIGHT 16
//#define Num_Candidate 25

extern int m_PlateWidth;
extern int m_PlateHeight;
//extern float m_Zoom;




typedef struct _Rect{
	int left;
	int right;
	int top;
	int bottom;
}Rect;

typedef struct
{
	int left;
	int top;
	int right;
	int bottom;
	int width;
	int height;
	double value;
} PLATE;

PLATE Set_Rect(int a,int b,int c,int d);
void SortDown(PLATE* Candidate,int count);
int convolute(int *arrhis, int widthgate, int *arrsup, int count);
void SearchTriangle(int* arrsup, int widthgate,short int* IsIndexY,int arrsupcount);
PLATE Inflate_Rect(PLATE A, int xLeft, int yTop,int xRight,int yBottom,char chdir,int i_width,int i_height);

class PlateDetect{
	
//private:
public:
	int max_plate_width;
	int max_plate_height;
	int min_plate_width;
	int min_plate_height;

	int m_PlateWidth;
	int m_PlateHeight;


	int i_width,i_height;
	unsigned char *image_gray, *image_edge;

	PLATE* PlateCandidate;
	int Num_Candidate;

	int max_limit_width; //110
	int max_limit_height;//30
	int min_limit_width; //60
	int min_limit_height; //12
	int max_ratio;//7
	int min_ratio;//3
	double threshold_value;

public:
	PlateDetect();
	~PlateDetect();
	PlateDetect(int width,int height);

	void Set_plate_WH(int maxwidth,int maxheight,int minwidth,int minheight);
	void Set_limit_WH(int maxwidth,int maxheight,int minwidth,int minheight,double value);
	void Getimage(unsigned char *image, int widthstep,int height);

	void CreateEdge(char TYPE);
	void SetMaxPlateWandH();
	void SetMinPlateWandH();
	double ValueStretch(uchar *picture, PLATE* pCandidate);
	int Project(uchar* picture,PLATE cplate,char chdir,int* arrHis);
	
	void Locate(unsigned char* buff);
	void stretch(PLATE* cPlate,int NumCandidate,unsigned char *buff);
	bool Detection(uchar* image_gray,uchar *buff,Rect *target);
	int IsPlate(uchar* edgeimg,int width,int height,PLATE platea);

};

#endif


